package com.cjjd.c.feature.mine.benefits;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.ActionBarFragment;
import com.cjjd.c.bean.CustomerCardDiscountBean;
import com.cjjd.c.bean.HotelQrCodeInfoBean;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.feature.dialog.TextDialog;
import com.cjjd.c.http.CallbackImpl;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.DialogUtil;
import com.cjjd.c.utils.ImageUtil;
import com.cjjd.c.utils.SharePrefUtil;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by dada on 2017/12/23.
 */

public class BenefitsFragment extends ActionBarFragment {
    @Bind(R.id.iv_card)
    ImageView ivCard;
    @Bind(R.id.zhekou)
    TextView zhekou;
    @Bind(R.id.layout_zhekou)
    LinearLayout layoutZhekou;
    @Bind(R.id.shuiguo)
    TextView shuiguo;
    @Bind(R.id.layout_shuiguo)
    LinearLayout layoutShuiguo;
    @Bind(R.id.tuifang)
    TextView tuifang;
    @Bind(R.id.layout_tuifang)
    LinearLayout layoutTuifang;
    @Bind(R.id.tv_current_point)
    TextView tv_current_point;

    String id;
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        id=getArguments().getString("id");
        String img=getArguments().getString("img");
        String name=getArguments().getString("name");

        ImageUtil.displayImage(img,ivCard);


        tonet();
    }


    private  void tonet(){


        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        h1.put("uuid", id);
        service.getCardDiscountInfo(JsonUtils.convertParam("getCardDiscountInfo", h1)).enqueue(new CallbackImpl<CustomerCardDiscountBean>() {
            @Override
            public void responseSuccess(Call<HttpResult<CustomerCardDiscountBean>> call, Response<HttpResult<CustomerCardDiscountBean>> response) {
                CustomerCardDiscountBean.CustomerCardDiscountMode bean=response.body().getData().customerCardDiscount;

                tv_current_point.setText(bean.memo);

                if(bean.isdiscountRate.equalsIgnoreCase("2")){
                    layoutZhekou.setVisibility(View.VISIBLE);
                    zhekou.setText(bean.discountRateMemo+"，当前折扣"+bean.discountRate+"折");
                }
                if(bean.isdelayFree.equalsIgnoreCase("2")){
                    layoutTuifang.setVisibility(View.VISIBLE);
                    tuifang.setText(bean.isdelayFreeMemo);
                }
                if(bean.isGiftFruit.equalsIgnoreCase("2")){
                    layoutShuiguo.setVisibility(View.VISIBLE);
                    shuiguo.setText(bean.isGiftFruitMemo);
                }

            }

            @Override
            public boolean onFaulure() {
                return false;
            }
        });
    }

    @Override
    public Object getTitleString() {
        return "会员福利";
    }

    @Override
    public int getContentView() {
        return R.layout.fragment_benefits;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
